/**
 * @class NG.controllers.Settings
 * @extends Ext.Controller
 * 
 * Settings controller. All settings operations are handled by this class.
 */
NG.controllers.Settings = Ext.extend(Ext.Controller, {
	
	/**
	 * All caches defined in NGCache are cleared.
	 * @param {Object} options
	 */
	clearCaches: function (options) {
		if (NGCache) {
			NGCache.clear();
		}
		//TODO diğer cache yapıları buraya eklenmeli 
	},
	
	/**
	 * @ignore
	 * @param options
	 */
	clearStore: function (options) {
		if (app.views.mapView.mapServer && app.views.mapView.mapServer.store)
			app.views.mapView.mapServer.store.clear();
		else 
			console.warn("Map View must be viewed.");
	},
	
	/**
	 * Saves the settings. Settings model type is NG.models.Settings.
	 * @param {Object} options
	 */
	save: function (options) {
		var settings = Ext.ModelMgr.create(options.form.getValues(), 'NG.models.Settings');
		NG.stores.settings.removeAll();
		NG.stores.settings.add(settings);
		NG.stores.settings.sync();
		Ext.Msg.alert('Başarılı', 'Kaydedildi', Ext.emptyFn);
		Ext.dispatch({
			controller: app.controllers.mapView,
			action: 'settingsChanged',
			settings: settings
		});		
	}
});

/**
 * app.controllers.settings is a constant.
 * @singleton app.controllers.settings
 */
app.controllers.settings = new NG.controllers.Settings();